home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993…stman Always Clicks Twice / ADC Developer CD (1993-01) (''The Postman Always Clicks Twice'')_iso / Dev.CD 199301.iso / Development Platforms / LISP Related / LISP Goodies / McCartney-library 1.1 / CODE / oodles-files / GWorld-view-extensions.lisp < prev    next >
Encoding:
Text File  |  1992-09-02  |  5.1 KB  |  155 lines  |  [TEXT/CCL2]

  1. ;;; GWorld-view-extensions.lisp
  2. ;;;
  3. ;;; Paul McCartney, Spring 1992
  4. ;;;
  5. ;;; Copyright © 1992 Paul McCartney.  All Rights Reserved.
  6. ;;; 
  7. ;;; Washington University Medical Informatics Training Program
  8. ;;;
  9. ;;; DESCRIPTION:
  10. ;;;
  11. ;;; This is a simple extension for using GWorld offscreen graphics
  12. ;;; provided by Michael S. Engber in his "oodles-of-utils" package.
  13. ;;;
  14. ;;; USE:
  15. ;;;
  16. ;;; *GW-offscreen-view*       -  the offscreen view used by this module
  17. ;;;
  18. ;;; GW-extensions-init        -  initialize this module
  19. ;;;
  20. ;;; GW-extensions-destroy     -  destroy data local to this module
  21. ;;;
  22. ;;; with-GWorld-no-colorization -  
  23. ;;;      A macro for offscreen drawing.  All things drawn inside this
  24. ;;;      macro and focused to "*GW-offscreen-view*" are drawn offscreen
  25. ;;;      and transfered instantaneously to the screen when the macro exits.
  26. ;;;      The colors are NOT colorized (i.e. copybits does not change the
  27. ;;;      colors between offscreen and onscreen).  See example below.
  28. ;;;
  29. ;;; make-GW-point             -  translate the onscreen view's coordinates
  30. ;;;                              to the offscreen view's coordinates.
  31. ;;;                              All graphics calls should use this function
  32. ;;;                              to compute point coordinates.
  33. ;;; HISTORY:
  34. ;;;
  35. ;;; 6/29/92  Created.  - PM
  36. ;;;
  37.  
  38. (in-package :oou)
  39.  
  40. (require :GWorld-view)
  41.  
  42. (eval-when (:compile-toplevel :load-toplevel :execute)
  43.   (export '(with-GWorld-no-colorization GW-extensions-init GW-extensions-destroy make-GW-point
  44.             *GW-offscreen-view*)
  45.           :oou))
  46.  
  47.  
  48. (defvar *GW-offscreen-view*)
  49. (defvar *GW-topleft*)
  50.  
  51.  
  52. ;;; Initialize a large offscreen GWorld for general purpose drawing.
  53. ;;;
  54. (defun GW-extensions-init (&optional (size (get-largest-screen-size)))
  55.   (setf *GW-offscreen-view*
  56.         (make-instance 'GWorld-view
  57.           :GW-depth 0
  58.           :view-position #@(0 0)
  59.           :view-size size))
  60.   (GW-alloc *GW-offscreen-view*) )
  61.  
  62.  
  63. ;;; Destroy the offscreen GWorld.
  64. ;;;
  65. (defun GW-extensions-destroy ()
  66.   (GW-free *GW-offscreen-view*))
  67.  
  68.  
  69. ;;; Return the largest horizontal and vertical screen sizes encoded as a point.
  70. ;;; Note that this doesn't necessarily correspond to one screen, each of h and v is 
  71. ;;; the largest of all the screens.
  72. ;;; 
  73. (defun get-largest-screen-size ()
  74.   (let ((size-h 0)
  75.         (size-v 0))
  76.     (do ((gd (#_GetDeviceList) (#_GetNextDevice gd)))
  77.         ((%null-ptr-p gd) (make-point size-h size-v))
  78.       (with-dereferenced-handles ((gd1 gd))
  79.         (let* ((gd-rect (pref gd1 Gdevice.gdRect))
  80.                (gd-size-h (- (rref gd-rect rect.right) (rref gd-rect rect.left)))
  81.                (gd-size-v (- (rref gd-rect rect.bottom) (rref gd-rect rect.top))))
  82.           (if (> gd-size-h size-h)
  83.             (setf size-h gd-size-h))
  84.           (if (> gd-size-v size-v)
  85.             (setf size-v gd-size-v)) )) )))
  86.  
  87.  
  88. ;;; A macro for offscreen drawing.  All things drawn inside this
  89. ;;; macro and focused to "*GW-offscreen-view*" are drawn offscreen
  90. ;;; and transfered instantaneously to the screen when the macro exits.
  91. ;;; The colors are NOT colorized (i.e. copybits does not change the
  92. ;;; colors between offscreen and onscreen).  See example below.
  93. ;;;
  94. (defmacro with-GWorld-no-colorization ((view left top right bottom &optional (mode #$srcCopy)) &body body)
  95.   `(rlet ((to-rect :rect :left ,left :top ,top :right ,right :bottom ,bottom)
  96.           (from-rect :rect :left 0 :top 0 :right (- ,right ,left) :bottom (- ,bottom ,top)))
  97.      (without-interrupts
  98.       (setf *GW-topleft* (make-point ,left ,top))
  99.       
  100.         (with-focused-view *GW-offscreen-view*
  101.           (with-back-color (rgb-to-color (rref (wptr ,view) cgrafport.rgbbkcolor))
  102.             (with-fore-color (rgb-to-color (rref (wptr ,view) cgrafport.rgbfgcolor))
  103.               (require-trap #_EraseRect from-rect)
  104.               ,@body)))
  105.         (with-locked-GWorld-view *GW-offscreen-view*
  106.           (with-focused-view ,view
  107.             (with-fore-color *black-color*
  108.               (with-back-color *white-color*
  109.                 (with-pointers ((sb (rref (wptr *GW-offscreen-view*) 
  110.                                           :GrafPort.portBits))
  111.                                 (db (rref (wptr ,view) :GrafPort.portBits)))
  112.                   (require-trap #_CopyBits sb db from-rect to-rect ,mode (%null-ptr))))))) )))
  113.  
  114.  
  115. (defun make-GW-point (h &optional v)
  116.   (if v
  117.     (subtract-points (make-point h v) *GW-topleft*)
  118.     (subtract-points h *GW-topleft*)))
  119.  
  120.  
  121. (provide :GWorld-view-extensions)
  122.  
  123.  
  124. #|
  125. ; Example
  126.  
  127. (in-package :oou)
  128.  
  129. (defvar w)
  130. (setf w (make-instance 'window 
  131.           :view-position #@(50 50)
  132.           :view-size #@(200 200)
  133.           :color-p t))
  134.  
  135. (set-back-color w *black-color*)
  136.  
  137. (defun draw-random-ovals (n)
  138.   (with-GWorld-no-colorization (w 0 0 200 200)
  139.     (dotimes (i n)
  140.       (let* ((topleft (make-point (random 200) (random 200)))
  141.              (bottomright (add-points topleft
  142.                                       (make-point (random 50) (random 50)))))
  143.         (with-fore-color (random *white-color*)
  144.           (rlet ((r :rect :topleft topleft :bottomright bottomright))
  145.             (#_PaintOval r)) )))))
  146.  
  147.  
  148. (dotimes (i 5)
  149.   (draw-random-ovals 50))
  150.  
  151. ;;; Do this next line when you are finished with the demo
  152. ;;;
  153. ; (GW-extensions-destroy)
  154.  
  155. |#